<?php
/**
 * 供应商模块tool
 *
 * @author    wangmx <wangmx@yunys.com.cn>
 * @copyright 2016 QuanZhouYunYiShang Inc.
 */
namespace App\Services\SupplierService;

use DB;

class SupplierTool
{

    /**
     * @return mixed
     * 获取所有供应商ID及名称
     */
    public static function getAllSupplier()
    {
        $lists = DB::table('suppliers')->where('state', 1)->select('supplier_id', 'supplier_name')->get()->toArray();
        return $lists;
    }

    /**
     * @param $supplier_id
     * @return array
     * 根据supplier_id获取供应商可提供模板
     */
    public static function getTempBySupplierID($supplier_id)
    {
        $temp_ids = DB::table('suppliers')->where('supplier_id', $supplier_id)->value('template_ids');
        $temp_ids_array = explode(",", $temp_ids);
        return $temp_ids_array;
    }

    /**
     * @param $supplier_id
     * @return bool
     * 根据supplier_id查找供应商是否存在
     */
    public static function isExistBySupplierID($supplier_id)
    {
        $isExist = DB::table('suppliers')->where(['supplier_id' => $supplier_id, 'state' => 1])->first();
        if ($isExist == null) {
            return false;
        } else {
            return true;
        }
    }
    public static function getNameBySupplierID($supplier_id)
    {
        $name = DB::table('suppliers')->where(
            ['supplier_id' => $supplier_id])
            ->value('supplier_name');
        return $name;
    }
}
